<template>
  <div class="app-container">
    <el-card>
      <div slot="header">
        <div class="tools-select">
          <el-row>
            <el-col>
              <el-button
                type="primary"
                size="mini"
                icon="el-icon-search"
                @click="handleQuery"
                >查询
              </el-button>
              <el-button
                type="info"
                size="mini"
                icon="el-icon-plus"
                @click="handleAdd"
                >新增
              </el-button>
            </el-col>
          </el-row>
        </div>
      </div>
      <!-- 表格区 -->
      <el-table size="mini" stripe :data="tableData" border>
        <el-table-column
          align="center"
          label="序号"
          type="index"
          width="50px"
        />
        <el-table-column align="center" label="逻辑连接符" prop="type" />
        <el-table-column align="center" label="源表名" prop="sourceTableName" />
        <el-table-column
          align="center"
          label="源表名注释"
          prop="sourceTableComment"
        />
        <el-table-column align="center" label="源列名" prop="sourceColName" />
        <el-table-column
          align="center"
          label="源列注释"
          prop="sourceColComment"
        />
        <el-table-column align="center" label="连接符" prop="related" />
        <el-table-column
          align="center"
          label="目标表名"
          prop="targetTableName"
        />
        <el-table-column
          align="center"
          label="目标表注释"
          prop="targetTableComment"
        />
        <el-table-column align="center" label="目标列名" prop="targetColName" />
        <el-table-column
          align="center"
          label="目标列注释"
          prop="targetColComment"
        />
        <el-table-column align="center" label="创建时间" prop="createTime"  width="200"/>
        <el-table-column align="center" label="操作" width="80">
          <template v-slot="scope">
            <el-button
              type="text"
              size="mini"
              icon="el-icon-delete"
              @click="handleDel(scope.row.id)"
              >删除
            </el-button>
          </template>
        </el-table-column>
      </el-table>
    </el-card>
    <EditDialog ref="edit" @onCallBack="handleQuery"></EditDialog>
  </div>
</template>

<script>
import { getList, deleteById } from "@/api/sysQueryRelevanceCondition";
import EditDialog from "./components/EditDialog";

export default {
  components: { EditDialog },
  props: ["id"],
  data() {
    return {
      tableData: [],
      page: {
        pageSize: 10,
        pageNum: 1,
        total: undefined,
      },
    };
  },
  mounted() {
    this.handleQuery();
  },
  methods: {
    handleQuery() {
      getList({
        pageSize: this.page.pageSize,
        pageNum: this.page.pageNum,
        mainId: this.id,
      }).then((res) => {
        this.tableData = res.data;
      });
    },
    handleAdd() {
      this.$refs["edit"].onShow(this.id);
    },
    handleDel(id) {
      deleteById(id).then((res) => {
        if (res.code === 20000) {
          this.handleQuery();
          this.$message({
            message: "操作成功",
            type: "success",
          });
        }
      });
    },
  },
};
</script>
<style scoped>
.el-pagination {
  float: left;
  padding-top: 20px;
  padding-bottom: 20px;
}

.tools-select {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background-color: #ffffff;
  padding: 10px;
  border: 1px;
  border-radius: 5px;
}
</style>
